﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using LevenBlog.Core.Entities;
using LevenBlog.Core.Service;
using LevenBlog.Core.WcfService;

namespace LevenBlog.WcfService {
    // NOTE: If you change the interface name "IBlogService" here, you must also update the reference to "IBlogService" in Web.config.
    [ServiceContract]
    public interface IBlogService {
        #region Blog相关

        /// <summary>
        /// 统计Blog条目
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [OperationContract]
        int CountBlog(int? categoryId, BlogState? state);

        /// <summary>
        /// 根据给定的时间范围统计blog条目
        /// </summary>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="state"></param>
        /// <returns></returns>
        [OperationContract]
        int CountBlogByDateTime(DateTime? startTime, DateTime? endTime, BlogState state);

        /// <summary>
        /// 根据tags名称统计blog条目,用于tags搜索分页
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [OperationContract]
        int CountBlogByTag(string tag, BlogState state);

        /// <summary>
        /// 根据查询关键字统计blog条目,用于搜索分页
        /// </summary>
        /// <param name="s"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [OperationContract]
        int CountBlogByTitle(string s, BlogState state);

        /// <summary>
        /// 获取blog列表信息
        /// </summary>
        /// <param name="categoryId">分类id,保持空为不限制</param>
        /// <param name="page">当前页码</param>
        /// <param name="state">blog筛选</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_blog> GetBlogList(int? categoryId, int page, BlogState state);

        /// <summary>
        /// 根据给定的时间范围获取blog列表
        /// </summary>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="page">页码</param>
        /// <param name="state">筛选条件</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_blog> GetBlogListByDateTime(DateTime? startTime, DateTime? endTime, int page, BlogState state);

        /// <summary>
        /// 根据给定的tag搜索获取blog条目
        /// </summary>
        /// <param name="tag">搜索tag关键字</param>
        /// <param name="page">当前页</param>
        /// <param name="state">筛选条件</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_blog> SearchBlogListByTag(string tag, int page, BlogState state);

        /// <summary>
        /// 根据给定的搜索关键字获取blog条目
        /// </summary>
        /// <param name="s">关键字</param>
        /// <param name="page">当前页</param>
        /// <param name="state">筛选条件</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_blog> SearchBlogListByTitle(string s, int page, BlogState state);

        /// <summary>
        /// 根据给定的id获取blog信息,用户blog数据显示页
        /// </summary>
        /// <param name="id">id信息</param>
        /// <returns></returns>
        [OperationContract]
        lb_blog GetBlog(int id);

        /// <summary>
        /// 根据给定的blogid获取该blog上下篇信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        Pair<lb_blog, lb_blog> GetAboutBlog(int id);

        /// <summary>
        /// 根据给定的年,月信息获取当月blog书写情况,返回的int数组代表书写情况,比如返回[1,5,25]则代表当月1号,5号,25号书写了blog,其他日期没有,用于日历显示
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        [OperationContract]
        int[] GetBlogWriteDays(int year, int month);

        /// <summary>
        /// 获取最新的blog,用于侧边显示
        /// </summary>
        /// <param name="num">最新数量</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_blog> GetTopBlogList(int num);

        /// <summary>
        /// 获取最新评论信息,用于侧边显示
        /// </summary>
        /// <param name="num">最新数量</param>
        /// <returns></returns>
        [OperationContract]
        List<lb_comment> GetTopCommentList(int num);

        /// <summary>
        /// 获取所有blog存档信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        List<lb_archive> GetArchive();

        #endregion

        #region 用户及需要权限操作的部分

        /// <summary>
        /// 用户登录,登陆成功后将返回一个加密的token信息,系统应保留该token信息,登录失败将返回String.Empty
        /// 所有需要权限的操作都必须提供该token信息
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [OperationContract]
        string Login(string username, string password);

        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <param name="token">用户登录凭证</param>
        /// <returns></returns>
        [OperationContract]
        lb_user GetCurrentUser(string token);

        /// <summary>
        /// 发表新的blog
        /// </summary>
        /// <param name="token">用户登录凭证</param>
        /// <param name="blog"></param>
        [OperationContract]
        void AddBlog(string token, lb_blog blog);

        /// <summary>
        /// 登录用户发表新的评论,游客发表请勿调用该API
        /// </summary>
        /// <param name="token">用户凭证</param>
        /// <param name="comment"></param>
        [OperationContract]
        void AddComment(string token, lb_comment comment);

        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="user"></param>
        [OperationContract]
        void UpdateUser(string token, lb_user user);

        /// <summary>
        /// 更新用户扩展信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="info"></param>
        [OperationContract]
        void UpdateUserInfo(string token, lb_userinfo info);

        /// <summary>
        /// 删除指定的blog
        /// </summary>
        /// <param name="token"></param>
        /// <param name="id"></param>
        [OperationContract]
        void DeleteBlog(string token, int id);

        /// <summary>
        /// 删除指定的评论信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="id"></param>
        [OperationContract]
        void DeleteComment(string token, int id);

        #endregion

        #region 基本信息

        /// <summary>
        /// 获取站点配置信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        lb_config GetConfig();

        /// <summary>
        /// 获取站点状态信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        lb_state GetState();

        #endregion

        #region 分类相关

        /// <summary>
        /// 获取所有导航分类信息
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        List<lb_category> GetCategories();

        #endregion

        #region 友情链接部分

        /// <summary>
        /// 获取首页显示的友情链接,用于侧边显示
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        List<lb_friendlink> GetIndexLinkList();

        /// <summary>
        /// 获取所有友情链接
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        List<lb_friendlink> GetLinkList();

        #endregion  
    }
}
